﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CameraUC
{
    public partial class SelectCameraForm : DevComponents.DotNetBar.Office2007Form
    {
        #region Attributs and Getter/Setter
        public EventHandler eventSelect;
        public EventHandler eventCancel;
        private List<FVIL.DS.CFviFilterInfo> m_listCamera;
        private string m_cameraIniPath;

        #endregion
        public SelectCameraForm(List<FVIL.DS.CFviFilterInfo> listCamera, string cameraIniPath)
        {
            InitializeComponent();
            m_listCamera = listCamera;
            m_cameraIniPath = cameraIniPath;
        }

        #region Logic function
        #endregion

        #region Events on form
        private void SelectCameraForm_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < m_listCamera.Count; i++)
            {
                cbListCamera.Items.Add(m_listCamera[i].Name);
            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (cbListCamera.SelectedIndex == -1)
            {
                MessageBox.Show("カメラを選択してください。", "警報" , MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            OnSelectClick();
            FVIL.DS.CFviGrabberParam param = new FVIL.DS.CFviGrabberParam();
            param.FilterInfo = m_listCamera[cbListCamera.SelectedIndex];
            param.Save(m_cameraIniPath);
            this.Close();
        }

        public virtual void OnSelectClick()
        {
            EventHandler handler = eventSelect;
            if (handler != null)
            {
                handler(null, EventArgs.Empty);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            OnCancelClick();
            this.Close();
        }

        public virtual void OnCancelClick()
        {
            EventHandler handler = eventCancel;
            if (handler != null)
            {
                handler(null, EventArgs.Empty);
            }
        }
        #endregion
    }
}
